import { createSlice } from "@reduxjs/toolkit";

import { AppState } from "@/types/store/app";


const initialState: AppState = { theme: localStorage.getItem("theme") || "light" };

const AppStore = createSlice({
  name: "app",
  initialState,
  reducers: {
    changeTheme(state, action) {
      localStorage.setItem("theme", action.payload);
      state.theme = action.payload;
    },
  },
});

export const { changeTheme } = AppStore.actions;

export default AppStore.reducer;
